/** init domain config */
import './config'

import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from './router'
import store from './store/'
import { VueAxios } from '@/utils/request'

require('@jeecg/antd-online-mini')
require('@jeecg/antd-online-mini/dist/OnlineForm.css')

import Antd, { version } from 'ant-design-vue'
console.log('ant-design-vue version:', version)

//20230301-begin

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n
import i18n from './i18n/i18n'
import '@/styles/index.scss' // global css
// import Vue from 'vue'
import { Message } from 'element-ui'

//定义一个新的Message方法，多传入一个offset参数，用于this.$messgae中修改offset中的初始值
let messageInstance = null
const $message = (options) => {
  // return Message({
  //   ...options,
  //   showClose: true
  // });
  if (messageInstance) {
    //判断是否有提示框，有则关闭
    messageInstance.close()
  }
  messageInstance = Message({
    ...options,
    showClose: true,
  })
  return messageInstance
}
//重写一遍success的方法,将offset写入options
;['success', 'warning', 'info', 'error'].forEach((type) => {
  $message[type] = (options) => {
    if (typeof options === 'string') {
      options = {
        message: options,
        showClose: true,
        duration: 1000,
      }
    }
    options.type = type
    return Message(options)
  }
})
//将$message挂载到this上
Vue.prototype.$elMessage = $message
// //如果用要使用 `this.$elMessage.closeAll()`则加上下面
// Vue.prototype.$elMessage.closeAll =Message.closeAll;

// Vue.prototype.$elMessage = Message
// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

import printPages from '@/utils/printPages.js'
Vue.use(printPages)

//引入日期工具类
import DateFormatterUtil from './utils/DateFormatter.js'

// 引入查询列配置方法
import setColumn from '@/utils/setColumn.js'
Vue.prototype.$setColumn = setColumn

import { formatMoney, formatPrice, formatNumber } from '@/utils/index'
Vue.prototype.$formatMoney = formatMoney
Vue.prototype.$formatPrice = formatPrice
Vue.prototype.$formatNumber = formatNumber

import { toBillDetail } from '@/utils/billUtil'
Vue.prototype.$toBillDetail = toBillDetail

// import VueResource from 'vue-resource'
// Vue.use(VueResource)

import '@/icons/index' // icon
import './utils/flexible.js'
import pinyin1 from './utils/PinYin.js'
import pinyin from './utils/ChinesePY.js'
Vue.prototype.$pinyin = pinyin

// import * as echarts from 'echarts'
import { conversion, lcStorage, seStorage, setTimeRange, regExpObj, formatDateTime } from './utils/c_public_method.js'
Vue.prototype.$conversion = conversion // 数值过大显示万
Vue.prototype.$lcStorage = lcStorage // localStorage数据存储
Vue.prototype.$seStorage = seStorage // sessionStorage数据存储
Vue.prototype.$setTimeRange = setTimeRange // 获取时间范围
Vue.prototype.$regExpObj = regExpObj // 正则判断
Vue.prototype.$formatDateTime = formatDateTime // 获取当天日期遇0自动补齐
Vue.prototype.$EventBus = new Vue()

import FileSaver from 'file-saver'
import XLSX from 'xlsx'
// Vue.prototype.$FileSaver = FileSaver
// Vue.prototype.$XLSX = XLSX
//日期工具类挂载到vue的原型对象上
Vue.prototype.$dateUtil = DateFormatterUtil

// import SvgIcon from '@/components/SvgIcon' // svg component
// register globally
// Vue.component('svg-icon', SvgIcon)

//20230301-end

import Viser from 'viser-vue'
import 'ant-design-vue/dist/antd.less' // or 'ant-design-vue/dist/antd.less'

import '@/permission' // permission control
import '@/utils/filter' // base filter
import Print from 'vue-print-nb-jeecg'
/*import '@babel/polyfill'*/
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
import SSO from '@/cas/sso.js'
import {
  ACCESS_TOKEN,
  DEFAULT_COLOR,
  DEFAULT_THEME,
  DEFAULT_LAYOUT_MODE,
  DEFAULT_COLOR_WEAK,
  SIDEBAR_TYPE,
  DEFAULT_FIXED_HEADER,
  DEFAULT_FIXED_HEADER_HIDDEN,
  DEFAULT_FIXED_SIDEMENU,
  DEFAULT_CONTENT_WIDTH_TYPE,
  DEFAULT_MULTI_PAGE,
  ACCOUNT_BOOK,
  OPEN_ACCOUNT_VALUE,
} from '@/store/mutation-types'
import config from '@/defaultSettings'

import JDictSelectTag from './components/dict/index.js'
import hasPermission from '@/utils/hasPermission'
import vueBus from '@/utils/vueBus'
import JeecgComponents from '@/components/jeecg/index'
import '@/assets/less/JAreaLinkage.less'
import VueAreaLinkage from 'vue-area-linkage'
import '@/components/jeecg/JVxeTable/install'
import '@/components/JVxeCells/install'
//表单验证
import { rules } from '@/utils/rules'
import { fromTextArea } from 'codemirror'
Vue.prototype.rules = rules
Vue.config.productionTip = false
Vue.use(Storage, config.storageOptions)
Vue.use(Antd)
Vue.use(VueAxios, router)
Vue.use(Viser)
Vue.use(hasPermission)
Vue.use(JDictSelectTag)
Vue.use(Print)
Vue.use(preview)
Vue.use(vueBus)
Vue.use(JeecgComponents)
Vue.use(VueAreaLinkage)

SSO.init(() => {
  main()
})
function main() {
  new Vue({
    router,
    store,
    i18n,
    mounted() {
      store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
      store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
      store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
      store.commit('TOGGLE_FIXED_HEADER', Vue.ls.get(DEFAULT_FIXED_HEADER, config.fixedHeader))
      store.commit('TOGGLE_FIXED_SIDERBAR', Vue.ls.get(DEFAULT_FIXED_SIDEMENU, config.fixSiderbar))
      store.commit('TOGGLE_CONTENT_WIDTH', Vue.ls.get(DEFAULT_CONTENT_WIDTH_TYPE, config.contentWidth))
      store.commit('TOGGLE_FIXED_HEADER_HIDDEN', Vue.ls.get(DEFAULT_FIXED_HEADER_HIDDEN, config.autoHideHeader))
      store.commit('TOGGLE_WEAK', Vue.ls.get(DEFAULT_COLOR_WEAK, config.colorWeak))
      store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
      store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
      store.commit('SET_MULTI_PAGE', Vue.ls.get(DEFAULT_MULTI_PAGE, config.multipage))
      store.commit('SET_OPEN_ACCOUNT_VALUE', Vue.ls.get(OPEN_ACCOUNT_VALUE))
    },
    render: (h) => h(App),
  }).$mount('#app')
}

// 防抖处理-立即执行
const on = Vue.prototype.$on
Vue.prototype.$on = function (event, func) {
  let timer
  let flag = true
  let newFunc = func
  if (event === 'click') {
    newFunc = function () {
      if (flag) {
        func.apply(this, arguments)
        flag = false
      }
      clearTimeout(timer)
      timer = setTimeout(function () {
        flag = true
      }, 700)
    }
  }
  on.call(this, event, newFunc)
}

